package com.ag.zrt.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ag.bean.TbInforType;
import com.ag.zrt.dao.TbInforTypeDAO;
import com.ag.zrt.service.InforTypeService;
import com.ag.common.IIDService;
import com.ag.common.IDUtil;

@Service("InforTypeService")
public class InforTypeServiceImpl implements InforTypeService {
	@Resource(name = "ZRTTbInforTypeDAO")
	private TbInforTypeDAO inforTypeDAO;
	@Resource(name = "iDServiceImpl")
	private IIDService idService;

	@Override
	public void delete(TbInforType infoType) {
		// TODO Auto-generated method stub
		TbInforType info = inforTypeDAO.findById(infoType.getItId());
		info.setA(IDUtil.DELETE);
		inforTypeDAO.attachDirty(info);

	}

	public void setInforTypeDAO(TbInforTypeDAO inforTypeDAO) {
		this.inforTypeDAO = inforTypeDAO;
	}

	public void setIdService(IIDService idService) {
		this.idService = idService;
	}

	@Override
	public List<TbInforType> findAll() {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		sb.append("from TbInforType it where it.a ="+IDUtil.PRESERVE);
		
		List<TbInforType> list = inforTypeDAO.findAll(sb.toString());
		
		for (TbInforType infoType : list) {
			infoType.setTbInformations(null);
		}
		
		return list;
	}

	@Override
	public TbInforType findById(String id) {
		// TODO Auto-generated method stub
		TbInforType info = inforTypeDAO.findById(id);
		return info;
	}

	@Override
	public String save(TbInforType infoType) throws Exception {
		// TODO Auto-generated method stub
		String id = idService.findTablePK(IDUtil.TB_INFORTYPE);
		infoType.setItId(id);
		infoType.setA(IDUtil.PRESERVE);
		inforTypeDAO.save(infoType);
		return id;

	}

	@Override
	public void update(TbInforType InfoType) {
		// TODO Auto-generated method stub

	}

}
